/**
 * Copyright (C) 2009 Lazaro Brito
 *
 * This file is part of jIRC.
 * 
 * jIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * jIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with jIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package org.lazaro.jirc.irc;

/**
 * @author Lazaro Brito
 * 
 */
public class Mode {
	private String positiveModes = "";

	public void setModes(String mode) {
		String appendType = mode.substring(0, 1);
		if(!appendType.equals("+") && !appendType.equals("-")) {
			throw new IllegalArgumentException("invalid mode append types!");
		}
		for(char c : mode.toCharArray()) {
			if(appendType.equals("+")) { // positive
				if(!positiveModes.contains(new String(new char[] { c }))) {
					positiveModes = new StringBuilder(positiveModes).append(c).toString();
				}
			} else { // negative
				if(positiveModes.contains(new String(new char[] { c }))) {
					positiveModes = positiveModes.replace(new String(new char[] { c }), "");
				}
			}
		}
	}

	public String getPositiveModes() {
		return positiveModes;
	}

	public String toString() {
		return positiveModes;
	}
}